<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><html:text name="sys.name" /></title>
<script type="text/javascript" src='<%=WEBPATH%>/scripts/adapter/prototype/prototype.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/scripts/prototype/prototype-ui.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/scripts/prototype/window.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/scripts/prototype/effects.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/UserMailAction.js?id=<%=generate%>'></script>
<script type="text/javascript" src='<%=WEBPATH%>/dwr/interface/UserMailBean.js?id=<%=generate%>'></script>
</head>
<body>
<script type="text/javascript">
function boxOnclick(id,flag){
	/***_$('id').value=id;
	_$('boxFlag').value=flag;
	ajaxAnywhere.getZonesToReload = function(url,submitButton) {
		return "emailMainAjaxAnyWhere";
	}
	ajaxAnywhere.substituteFormSubmitFunction();
	ajaxAnywhere.substituteSubmitButtonsBehavior(true);***/ 
	
	jQuery('#boxFlag').val(flag);
	jQuery('#id').val(id);
	_$("listDataForm").submit();
}
function mailBoxClick(id){ 
	var lastClickId=jQuery('#lastClickId').attr("value");
	if(lastClickId==""){
		jQuery('#lastClickId').val(id); 
		jQuery("#table_"+id).show();
		UserMailAction.dwrView(id,mailBoxData);
	}else{
		if(lastClickId==id){
			jQuery('#lastClickId').val(id);
		}else{
			jQuery("#table_"+lastClickId).hide();
			jQuery("#table_"+id).show();
			jQuery('#lastClickId').val(id);
			UserMailAction.dwrView(id,mailBoxData);
		}
	}
	
}
function imgOnclick(orderBy,asc){
	jQuery("#orderBy").val(orderBy);
	jQuery("#asc").val(asc);
	_$("listDataForm").submit();
}
function mailBoxData(data){
	jQuery('#userId').val(data.userId);
	jQuery('#id').val(data.id);
	jQuery('#title').val(data.title);
	jQuery('#userName').val(data.userName);
	jQuery('#password').val(data.password);
	jQuery('#smtpHostName').val(data.smtpHostName);  
	if(data.smtpSSL==1){
		_$('smtpSSL').checked=true;
	}
	jQuery('#smtpPort').val(data.smtpPort);
	jQuery('#popHostName').val(data.popHostName);  
	if(data.popSSL==1){
		_$('popSSL').checked=true;
	}
	
	jQuery('#popPort').val(data.popPort);
	jQuery('#MailSet').show();
	jQuery('#saveBtn').show();
	jQuery('#deleteBtn').show();
	jQuery('#mainMail').hide();
}
function saveClick(){ 
	var smtpssl="0",popssl="0";
	if(_$('smtpSSL').checked==true){
		smtpssl="1";
	}
	if(_$('popSSL').checked==true){
		popssl="1";
	}
	var UserMailBean={
		id : jQuery('#id').attr("value"),	
		userId : jQuery('#userId').attr("value"),	
		title : jQuery('#title').attr("value"),	
		userName : jQuery('#userName').attr("value"),	
		password : jQuery('#password').attr("value"),	
		smtpHostName : jQuery('#smtpHostName').attr("value"),	
		smtpSSL : smtpssl,	
		smtpPort : jQuery('#smtpPort').attr("value"),	
		popHostName : jQuery('#popHostName').attr("value"),	
		popSSL : popssl,	
		popPort : jQuery('#popPort').attr("value") 
	};
	UserMailAction.dwrSave(UserMailBean,saveCallBack);
}
function newClick(){
	jQuery('#MailSet').show();
	jQuery('#saveBtn').show();
	jQuery('#userId').val("<html:property value='userIdUserMail'/>");
	jQuery('#id').val("");
	jQuery('#title').val("");
	jQuery('#userName').val("");
	jQuery('#password').val("");
	jQuery('#smtpHostName').val("");   
	_$('smtpSSL').checked=false;
	jQuery('#smtpPort').val("");
	jQuery('#popHostName').val("");   
	_$('popSSL').checked=false;
	
	jQuery('#popPort').val("");
	jQuery('#deleteBtn').hide();
	jQuery('#mainMail').hide();
}
function recieveClick(id){
	dwr.util.useLoadingMessage();
	UserMailAction.dwrReceiveMail(id,recieveCallClick);
}
function recieveCallClick(data){
	if(data=="success"){
		alert("<html:text name="entity.receive"/>");
	}else{
		alert("<html:text name="entity.receive.error"/>");
	}
}
function saveCallBack(data){
	if(data=="success"){
		if(jQuery('#id').attr("value")==""){
			alert("<html:text name="entity.saved"/>"); 
		}else{
			alert("<html:text name="entity.updated"/>");  
		}
		_$("listDataForm").submit(); 
	}else{
		if(jQuery('#id').attr("value")==""){
			alert("<html:text name="entity.saved.error"/>");
		}else{
			alert("<html:text name="entity.updated.error"/>");
		}
	}		
}
function delRole(){
	var id=jQuery('#id').attr("value");
	UserMailAction.dwrDelete(id,deleteCallBack);
}
function deleteCallBack(data){
	if(data=="success"){
		alert("<html:text name="entity.deleted"/>");
		_$("listDataForm").submit(); 
	}else{
		alert("<html:text name="entity.deleted.error"/>");
	}
}
function tdclick(id){ 
}
</script>
<form id="listDataForm" action="index.crm" method="post">
<table width="100%" style="height:90%;">
	<tr>
		<td width="15%" valign="top"><html:hidden
			id="boxFlag" name="boxFlag" /><html:hidden
			id="asc" name="asc" /><html:hidden
			id="orderBy" name="orderBy" /><input type="hidden" id="lastClickId" name="lastClickId"></input>
		<html:iterator value="userMailBeans" id="userMailBeans">
			<b style="cursor:pointer;" onclick="javascript:mailBoxClick('<html:property value="id" />');"><html:if test="title==null">
						<html:property value="userName" />
					</html:if><html:else>
						<html:property value="title" />
					</html:else></b>&nbsp;<a onclick="javascript:recieveClick('<html:property value="id" />');" href="#"><html:text name="mail.receive"/><html:text name="mail.mail"/></a>
			<table width="100%" id="table_<html:property value="id" />" style="display:none;"> 
				<tr>
					<td style="cursor:pointer;" onclick="javascript:boxOnclick('<html:property value="id" />',1);">&nbsp;&nbsp;<html:text name="userMail.receiveBox" /></td>
				</tr>
				<tr>
					<td style="cursor:pointer;" onclick="javascript:boxOnclick('<html:property value="id" />',4);">&nbsp;&nbsp;<html:text name="userMail.draftBox" /></td>
				</tr>
				<tr>
					<td style="cursor:pointer;" onclick="javascript:boxOnclick('<html:property value="id" />',3);">&nbsp;&nbsp;<html:text name="userMail.sentBox" /></td>
				</tr>
				<tr>
					<td style="cursor:pointer;" onclick="javascript:boxOnclick('<html:property value="id" />',5);">&nbsp;&nbsp;<html:text name="userMail.deleteBox" /></td>
				</tr>
			</table>
			<br />
		</html:iterator>
		</td>
		<td id="MailSet" width="85%"  valign="top" style="display:none;">
			<table width="100%">
			<tr>
				<td><html:text name="userMail.userName"></html:text><html:hidden name="id" id="id"></html:hidden></td>
				<td><html:textfield name="userName" id="userName" cssStyle="width:90%"></html:textfield></td>
				<td><html:text name="userMail.password"></html:text></td>
				<td><html:password name="password" id="password" cssStyle="width:90%"/></td>
			</tr>
			<tr>
				<td><html:text name="userMail.title"></html:text><html:hidden name="userId" id="userId"></html:hidden></td>
				<td ><html:textfield name="title" id="title" cssStyle="width:90%"></html:textfield></td>
				<td><html:text name="userMail.smtpHostName"></html:text></td>
				<td><html:textfield name="smtpHostName" id="smtpHostName" cssStyle="width:90%"></html:textfield></td>
			</tr>
			<tr>
				<td><html:text name="userMail.smtpPort"></html:text></td>
				<td><html:textfield name="smtpPort" id="smtpPort" cssStyle="width:90%"></html:textfield></td>
				<td><html:text name="userMail.smtpSSL"></html:text></td>
				<td><html:checkbox name="smtpSSL" id="smtpSSL" /></td>
			</tr>
			<tr>
				<td><html:text name="userMail.popHostName"></html:text></td>
				<td><html:textfield name="popHostName" id="popHostName" cssStyle="width:90%"></html:textfield></td>
				<td><html:text name="userMail.popPort"></html:text></td>
				<td><html:textfield name="popPort" id="popPort" cssStyle="width:90%"></html:textfield></td>
			</tr> 
			<tr>
				<td><html:text name="userMail.popSSL"></html:text></td>
				<td colspan="3"><html:checkbox name="popSSL" id="popSSL" /></td>
				
			</tr> 
			<tr><td colspan="4" align="right">&nbsp;&nbsp; &nbsp; &nbsp;<input 
					id="saveBtn" name="saveBtn" type="button" 
					value=" <html:text name="button.save"></html:text> "
					style="width: 90px" onclick="javascript:saveClick();"></input> &nbsp; &nbsp; &nbsp;<input
					name="deleteBtn" id="deleteBtn" type="button"  
					value=" <html:text name="button.delete"></html:text> "
					style="width: 90px" onclick="javascript:delRole();"></input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			</table>
		</td>
		<td id="mainMail" width="85%" valign="top"><input 
					id="newBtn" name="newBtn" type="button" 
					value=" <html:text name="button.new"/><html:text name="mail.box"/> "
					style="width: 90px" onclick="javascript:newClick();">&nbsp;&nbsp;&nbsp;&nbsp;<input 
					id="deleteBtn" name="deleteBtn" type="button" 
					value=" <html:text name="button.delete"/><html:text name="mail.mail"/> "
					style="width: 90px" onclick="javascript:deleteClick();"> 
			<table width="100%" class="datatable">
				<thead>
					<tr><td align="left" width="80"><input type="checkbox"
					id="checkList" onclick="javascript:onSelectChange(this);"><html:text
					name="entity.choose" /></td>
					<html:if test="boxFlag==4||boxFlag==3">
						<td width="80"><html:text name="mail.receiverName"></html:text></td> 
					</html:if>
					<html:else>
					<td width="80"><html:text name="mail.sender"></html:text></td>
					</html:else>
					<td  align="left" style="cursor:pointer;"
					<html:if test="asc"> onclick="javascript:imgOnclick('TITLE_',false);"</html:if>
					<html:else> onclick="javascript:imgOnclick('TITLE_',true);"</html:else>><html:text
					name="mail.subject" /><html:if test="orderBy=='TITLE_'">&nbsp;<img
						class="sort-arrow"
						<html:if test="asc"> src="<%=WEBPATH%>/images/arrow_up.png"</html:if>
						<html:else> src="<%=WEBPATH%>/images/arrow_down.png"</html:else> />
				</html:if></td> 
				<td  align="left" width="120" style="cursor:pointer;"
					<html:if test="asc"> onclick="javascript:imgOnclick('RECEIVEDATE',false);"</html:if>
					<html:else> onclick="javascript:imgOnclick('RECEIVEDATE',true);"</html:else>><html:text
					name="mail.date" /><html:if test="orderBy=='RECEIVEDATE'">&nbsp;<img
						class="sort-arrow"
						<html:if test="asc"> src="<%=WEBPATH%>/images/arrow_up.png"</html:if>
						<html:else> src="<%=WEBPATH%>/images/arrow_down.png"</html:else> />
				</html:if></td>  
					</tr>
				</thead>
				<html:if test="userReceiveMainBeanPages.result==null">
				<tbody>
					<tr>
						<td colspan="4"><html:text name="global.page.emptyMsg" /></td>
					</tr>
				</tbody> 
			</html:if>
			<html:else>
				<html:iterator id="users" value="userReceiveMainBeanPages.result"
					status="index">
					<tbody> 
						<tr <html:if test="#index.odd">class="row_odd"</html:if>
							<html:else>class="row_even"</html:else> <html:if test="readFlag==-1">style="font-weight:700;"</html:if>>
							<td align="left"><input type="checkbox" id="selectCheck"
								name="selectCheck" value="<html:property value="id"/>"></input><html:property value="#index.count"/></td> 
							<td align="left"><html:iterator value="userReceiveMailBeans" id="userReceiveMailBeans"><html:text name="fromName"></html:text></html:iterator></td>
							<td align="left"><html:property value="title" /></td>
							<td align="left"><html:text name="global.format.date"><html:param value="receiveDate"/></html:text></td>
						</tr>
					</tbody>
				</html:iterator>
				<tr class="tfoot">
					<td colspan="4" align="right" valign="top"><script
						type="text/javascript">
						messages=new Array();
						messages[0]="<html:text name="global.page.first" />";
						messages[1]="<html:text name="global.page.prev" />";
						messages[2]="<html:text name="global.page.next" />";
						messages[3]="<html:text name="global.page.last" />";
						messages[4]="<html:text name="global.page.page" />";
						messages[5]="<html:text name="global.page.everyPage" />";
						messages[6]="<html:text name="global.page.total" />";
						messages[7]="<html:text name="global.page.record" />";
						messages[8]="<html:text name="global.page.primo" />";
						writePage(messages,"<%=WEBPATH%>","<html:property value="userReceiveMainBeanPages.pageNo"/>","<html:property value="userReceiveMainBeanPages.totalPages"/>","<html:property value="userReceiveMainBeanPages.pageSize"/>");
						
					</script></td>
				</tr>
			</html:else>
			</table> 
		</td>
	</tr>
</table>
</form>
</body>
</html>